﻿using static System.Math;
abstract class Shape
{
    abstract public double Area();
    abstract public bool Judge();
}
class Rectangle : Shape
{
    double length;
    double width;
    public Rectangle(double length, double width)
    {
        this.length = length;
        this.width = width;
    }
    public override bool Judge()
    {
        if (width <= 0 || length <= 0)
        {
            Console.WriteLine("形状非法");
            return false;
        }
        else
            return true;
    }
    
    public override double Area()
    {
       
        if (Judge())
            return length*width;
        return -1;
    }
    

}

class Square : Shape
{
    double a;
    
    public Square(double a)
    {
        this.a = a;       
    }
    public override double Area()
    {
        return a*a;
    }
    public override bool Judge()
    {
        if (a <= 0 )
        {
            Console.WriteLine("形状非法");
            return false;
        }
        return true;
    }

}

class Triangle : Shape
{
    double a;
    double b;
    double c;
    public Triangle(double a, double b,double c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    
    public override bool Judge()
    {
        if (a+b<=c || a+c<=b || b+c<=a || a<=0 ||b<=0 || c<=0)
        {
            Console.WriteLine("形状非法");
            return false;
        }
        return true;
    }
    public override double Area()
    {
        if (Judge())
        {
            double p = (a + b + c) / 2;
            return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
        }
        else
            return -1;
        
    }
}

public class Program
{
    public static void Main(String[] args)
    {
        Rectangle rec = new Rectangle(10,20);
        Square squ = new Square(30);
        Triangle tri = new Triangle(1, 2, 10);
        tri.Judge();
        Console.WriteLine(tri.Area());
    }
}